
"""
3.4 循环结构—`while`循环与终止条件
while 条件表达式:
    条件执行体（循环体）
"""
flag = True
while flag:
    print("hello,world")
    flag = False
print("=== 退出循环 ==")

# 终止while循环的形式
#）修改条件表达式的变量
num = 10
while num > 0:
    print(num)
    num -= 1
print("=== 修改条件表达式的变量->退出循环 ==")

# 2) break退出循环
num = 10
while num > 0:
    print(num)
    if num % 5 !=0 :
        break
    num -= 1
print("===  break:退出循环 ==")

# return 方式退出循环
def test():
    num = 10
    while num > 0:
        print(num)
        if num % 5!=0 :
            return
        num -= 1
print("===  return:退出循环 ==")
test()

# while ....else...
num = 10
while num > 0:
    print(num)
    num -= 1
else:
    print("循环正常结束")
print("===  while....else... ==")